package com.sg.java.util;

import com.sg.java.entity.*;
import com.sg.java.enums.VoltageLevelEnum;
import org.apache.commons.lang3.StringUtils;

import java.util.*;
import java.util.stream.Collectors;

public class FormulaUtils {

    public static void IsVoltageQualified(VoltageQualified voltage, Integer index, StringJoiner stringJoiner, ArrayList<MaxAndMin> maxAndMins) {
        Double monitorTime = voltage.getMonitorTime();
        Double upTime = voltage.getUpTime();
        Double downTime = voltage.getDownTime();
//        Double totalU = voltage.getTotalU();
        Double notNullPoint = voltage.getNotNullPoint();
        Double effectiveDataTime = voltage.getEffectiveDataTime();
        Integer dyCount = voltage.getDyCount();

        /**
         * 关于倍率 24个点的话一个点是60分钟 所以倍率为4  96个点为1
         */
        Integer bl = 1;
        if (dyCount == 96) {
            bl = 1;
        } else if (dyCount == 24) {
            bl = 4;
        } else if (dyCount == 48) {
            bl = 2;
        } else if (dyCount == 4) {
            bl = 24;
        } else if (dyCount == 1) {
            bl = 96;
        }
        Double u = voltage.getVoltage();
        Double effectiveDataUper = voltage.getEffectiveDataUper();
        Double effectiveDataLower = voltage.getEffectiveDataLower();
        //  判断电压有效
        //判断当前电压值是否有效 有效则有效时间累加 进入下面累加越限时间方法 无效则退出统计方法
        if (u > effectiveDataLower && u < effectiveDataUper) {
            effectiveDataTime += 15 * bl;
            voltage.setEffectiveDataTime(effectiveDataTime);
        }else {
            return;
        }
        MaxAndMin maxAndMin = new MaxAndMin();
        maxAndMin.setVolt(u);
        maxAndMin.setIndex(index);
        maxAndMins.add(maxAndMin);

        //填充用户配变长期 严重集合
        yhLongTimeUper(voltage, bl,dyCount);
        yhLongTimeDown(voltage, bl,dyCount);
        yhYzDown(voltage, bl);
        yhYzUp(voltage, bl);
        //判断当前电压
        if (u > voltage.getUp()) { //230
            upTime += 15 * bl;
            //越上限电压值时刻
            voltage.getUpBuilder().append(voltage.getIndex().toString()).append(",");
            voltage.setUpTime(upTime);
        }
        if (u < voltage.getDown()) { //190
            downTime += 15 * bl;
            //越下限电压值时刻
            voltage.getDownBuilder().append(voltage.getIndex().toString()).append(",");
            voltage.setDownTime(downTime);
        }
        if (u < voltage.getUp() && u > voltage.getDown()) {
            voltage.setGaoSum(0);
            voltage.setDiSum(0);
            voltage.setYzGaoSum(0);
            voltage.setYzDiSum(0);
            voltage.setIsYX("0");
        }
//        sumHoursMonTime(voltage.getMonitoringTimeList(), index, bl);
        monitorTime += 15 * bl;
        voltage.setMonitorTime(monitorTime);
        if (dyCount == 96) {
            if (voltage.getGaoSum() >= 4) {
                if (!stringJoiner.toString().contains("1")) {
                    stringJoiner.add("1");
                }
            }
            if (voltage.getDiSum() >= 4) {
                if (!stringJoiner.toString().contains("2")) {
                    stringJoiner.add("2");
                }
            }
            if (voltage.getYzGaoSum() >= 4) {
                if (!stringJoiner.toString().contains("3")) {
                    stringJoiner.add("3");
                }
            }
            if (voltage.getYzDiSum() >= 4) {
                if (!stringJoiner.toString().contains("4")) {
                    stringJoiner.add("4");
                }
            }
        } else if (dyCount == 24) {
            if (voltage.getGaoSum() >= 1) {
                if (!stringJoiner.toString().contains("1")) {
                    stringJoiner.add("1");
                }
            }
            if (voltage.getDiSum() >= 1) {
                if (!stringJoiner.toString().contains("2")) {
                    stringJoiner.add("2");
                }
            }
            if (voltage.getYzGaoSum() >= 1) {
                if (!stringJoiner.toString().contains("3")) {
                    stringJoiner.add("3");
                }
            }
            if (voltage.getYzDiSum() >= 1) {
                if (!stringJoiner.toString().contains("4")) {
                    stringJoiner.add("4");
                }
            }

        } else if (dyCount == 48) {
            if (voltage.getGaoSum() >= 2) {
                if (!stringJoiner.toString().contains("1")) {
                    stringJoiner.add("1");
                }
            }
            if (voltage.getDiSum() >= 2) {
                if (!stringJoiner.toString().contains("2")) {
                    stringJoiner.add("2");
                }
            }
            if (voltage.getYzGaoSum() >= 2) {
                if (!stringJoiner.toString().contains("3")) {
                    stringJoiner.add("3");
                }
            }
            if (voltage.getYzDiSum() >= 2) {
                if (!stringJoiner.toString().contains("4")) {
                    stringJoiner.add("4");
                }
            }

        } else if (dyCount == 4) {
            if (voltage.getGaoSum() >= 1) {
                if (!stringJoiner.toString().contains("1")) {
                    stringJoiner.add("1");
                }
            }
            if (voltage.getDiSum() >= 1) {
                if (!stringJoiner.toString().contains("2")) {
                    stringJoiner.add("2");
                }
            }
            if (voltage.getYzGaoSum() >= 1) {
                if (!stringJoiner.toString().contains("3")) {
                    stringJoiner.add("3");
                }
            }
            if (voltage.getYzDiSum() >= 1) {
                if (!stringJoiner.toString().contains("4")) {
                    stringJoiner.add("4");
                }
            }

        } else if (dyCount == 1) {
            if (voltage.getGaoSum() >= 1) {
                if (!stringJoiner.toString().contains("1")) {
                    stringJoiner.add("1");
                }
            }
            if (voltage.getDiSum() >= 1) {
                if (!stringJoiner.toString().contains("2")) {
                    stringJoiner.add("2");
                }
            }
            if (voltage.getYzGaoSum() >= 1) {
                if (!stringJoiner.toString().contains("3")) {
                    stringJoiner.add("3");
                }
            }
            if (voltage.getYzDiSum() >= 1) {
                if (!stringJoiner.toString().contains("4")) {
                    stringJoiner.add("4");
                }
            }
        }
//        voltage.setTotalU(totalU + u);
    }


    public static void IsVoltageQualified2(VoltageQualified voltage, Integer index, ArrayList<MaxAndMin> maxAndMins) {
        Double monitorTime = voltage.getMonitorTime();
        Double upTime = voltage.getUpTime();
        Double downTime = voltage.getDownTime();
        Double effectiveDataTime = voltage.getEffectiveDataTime();
        Integer dyCount = voltage.getDyCount();
        Integer bl = 1;
        if (dyCount > 24) {
            bl = 1;
        } else {
            bl = 4;
        }
        Double u = voltage.getVoltage();
        Double effectiveDataUper = voltage.getEffectiveDataUper();
        Double effectiveDataLower = voltage.getEffectiveDataLower();
        //  判断电压有效
        if (u > effectiveDataLower && u < effectiveDataUper) {
            effectiveDataTime += 15 * bl;
            voltage.setEffectiveDataTime(effectiveDataTime);
        } else if (u < effectiveDataLower || u > effectiveDataUper) {
            return;
        }
        //填充用户配变长期 严重集合
        yhLongTimeUper2(voltage);
        yhLongTimeDown2(voltage);
        yhYzDown2(voltage);
        yhYzUp2(voltage);
        /**
         * 合格率：
         * 1.越限时间
         * 连续两个及两个以上数据点都越限则判为越限，
         * 越限时间为（N-1）*采集间隔，
         * 一个点越限则不判为越限（前后数据正常情况）。
         * 2.监测时间
         * 就是最后一个点的越线，要看他前面的点越线不越线
         */
        if (u > voltage.getUp()) {
            //最后一个点的监测时间暂不开启
//            Double lastMonitorTime = setLastMonitorTime(index, listSize, voltage, bl, monitorTime,1);
//            voltage.setMonitorTime(lastMonitorTime);
            if (voltage.getIsYx() != null && voltage.getIsYx().equals(1)) {
                upTime += 15 * bl;
                //越上限电压值时刻
                voltage.getUpBuilder().append(voltage.getIndex().toString()).append(",");
                voltage.setUpTime(upTime);
            }
            voltage.setIsYx(1);
        }
        if (u < voltage.getDown()) { //190
            //最后一个点的监测时间暂不开启
//            Double lastMonitorTime = setLastMonitorTime(index, listSize, voltage, bl, monitorTime,2);
//            voltage.setMonitorTime(lastMonitorTime);
            if (voltage.getIsYx() != null && voltage.getIsYx().equals(2)) {
                downTime += 15 * bl;
                //越下限电压值时刻
                voltage.getDownBuilder().append(voltage.getIndex().toString()).append(",");
                voltage.setDownTime(downTime);
            }
            voltage.setIsYx(2);
        }
        //如果当前电压为正常点数则归零越限标记
        if (u < voltage.getUp() && u > voltage.getDown()) {
            //最后一个点的监测时间暂不开启
//            Double lastMonitorTime = setLastMonitorTime(index, listSize, voltage, bl, monitorTime,null);
//            voltage.setMonitorTime(lastMonitorTime);
            voltage.setIsYx(0);
        }

        /**
         * 就是最后一个点的越线，要看他前面的点越线不越线
         */
        //最后一个点的监测时间暂不开启
//        if (index != listSize - 1){
//            monitorTime += 15 * bl;
//            voltage.setMonitorTime(monitorTime);
//        }
//        sumHoursMonTime(voltage.getMonitoringTimeList(),index,bl);
        monitorTime += 15 * bl;
        voltage.setMonitorTime(monitorTime);
//                double u = Double.parseDouble(v);

        //设置电压最大最小值(包含无效数据,最大最小值不进行优化)
        MaxAndMin maxAndMin = new MaxAndMin();
        maxAndMin.setVolt(u);
        maxAndMin.setIndex(index);
        maxAndMins.add(maxAndMin);
//        setMaxAndMin(voltage,index);
        //计算电压平均值相关
        voltage.setTotalU(voltage.getTotalU() + u);
        voltage.setNotNullPoint(voltage.getNotNullPoint() + 1);
    }

    public static void yhLongTimeUper2(VoltageQualified voltageQualified) {
        StringJoiner highVoltage = voltageQualified.getHighVoltage();
        //获取当前电压值
        Double voltage = voltageQualified.getVoltage();
        ArrayList<Integer> yhLongTimeUperArray = voltageQualified.getYhLongTimeUperArray();
        Integer index = voltageQualified.getIndex();
        if (voltage > voltageQualified.getUp()) {
            highVoltage.add(index + ":" + voltage);
            yhLongTimeUperArray.add(index);
        }
    }

    //填充用户配变长期越下集合
    public static void yhLongTimeDown2(VoltageQualified voltageQualified) {
        Double voltage = voltageQualified.getVoltage();
        StringJoiner lowVoltage = voltageQualified.getLowVoltage();
        ArrayList<Integer> yhLongTimeDownArray = voltageQualified.getYhLongTimeDownArray();
        Integer index = voltageQualified.getIndex();
        if (voltage < voltageQualified.getDown()) {
            lowVoltage.add(index + ":" + voltage);
            yhLongTimeDownArray.add(index);
        }
    }

    //填充用户配变严重越上集合
    public static void yhYzUp2(VoltageQualified voltageQualified) {
        Double voltage = voltageQualified.getVoltage();
        StringJoiner severeHighVoltage = voltageQualified.getSevereHighVoltage();
        ArrayList<Integer> yhSeverityUperArray = voltageQualified.getYhSeverityUperArray();
        Integer index = voltageQualified.getIndex();
        if (voltage > voltageQualified.getYzYhPbUper()) {
            severeHighVoltage.add(index + ":" + voltage);
            yhSeverityUperArray.add(index);
        }
    }

    //填充用户配变严重越下集合
    public static void yhYzDown2(VoltageQualified voltageQualified) {
        Double voltage = voltageQualified.getVoltage();
        ArrayList<Integer> yhSeverityDownArray = voltageQualified.getYhSeverityDownArray();
        StringJoiner severelyLowVoltage = voltageQualified.getSeverelyLowVoltage();
        Integer index = voltageQualified.getIndex();
        if (voltage < voltageQualified.getYzYhPbDown()) {
            severelyLowVoltage.add(index + ":" + voltage);
            yhSeverityDownArray.add(index);
        }
    }


    //累加每个小时的监测时间
    public static void sumHoursMonTime(List<Integer> list, Integer index, Integer bl) {
        if (index >= 1 && index < 5) {
            Integer integer = list.get(0);
            list.set(0, integer + 15 * bl);
        }
        if (index >= 5 && index < 9) {
            Integer integer = list.get(1);
            list.set(1, integer + 15 * bl);
        }
        if (index >= 9 && index < 13) {
            Integer integer = list.get(2);
            list.set(2, integer + 15 * bl);
        }
        if (index >= 13 && index < 17) {
            Integer integer = list.get(3);
            list.set(3, integer + 15 * bl);
        }
        if (index >= 17 && index < 21) {
            Integer integer = list.get(4);
            list.set(4, integer + 15 * bl);
        }
        if (index >= 21 && index < 25) {
            Integer integer = list.get(5);
            list.set(5, integer + 15 * bl);
        }
        if (index >= 25 && index < 29) {
            Integer integer = list.get(6);
            list.set(6, integer + 15 * bl);
        }
        if (index >= 29 && index < 33) {
            Integer integer = list.get(7);
            list.set(7, integer + 15 * bl);
        }
        if (index >= 33 && index < 37) {
            Integer integer = list.get(8);
            list.set(8, integer + 15 * bl);
        }
        if (index >= 37 && index < 41) {
            Integer integer = list.get(9);
            list.set(9, integer + 15 * bl);
        }
        if (index >= 41 && index < 45) {
            Integer integer = list.get(10);
            list.set(10, integer + 15 * bl);
        }
        if (index >= 45 && index < 49) {
            Integer integer = list.get(11);
            list.set(11, integer + 15 * bl);
        }
        if (index >= 49 && index < 53) {
            Integer integer = list.get(12);
            list.set(12, integer + 15 * bl);
        }
        if (index >= 53 && index < 57) {
            Integer integer = list.get(13);
            list.set(13, integer + 15 * bl);
        }
        if (index >= 57 && index < 61) {
            Integer integer = list.get(14);
            list.set(14, integer + 15 * bl);
        }
        if (index >= 61 && index < 65) {
            Integer integer = list.get(15);
            list.set(15, integer + 15 * bl);
        }
        if (index >= 65 && index < 69) {
            Integer integer = list.get(16);
            list.set(16, integer + 15 * bl);
        }
        if (index >= 69 && index < 73) {
            Integer integer = list.get(17);
            list.set(17, integer + 15 * bl);
        }
        if (index >= 73 && index < 77) {
            Integer integer = list.get(18);
            list.set(18, integer + 15 * bl);
        }
        if (index >= 77 && index < 81) {
            Integer integer = list.get(19);
            list.set(19, integer + 15 * bl);
        }
        if (index >= 81 && index < 85) {
            Integer integer = list.get(20);
            list.set(20, integer + 15 * bl);
        }
        if (index >= 85 && index < 89) {
            Integer integer = list.get(21);
            list.set(21, integer + 15 * bl);
        }
        if (index >= 89 && index < 93) {
            Integer integer = list.get(22);
            list.set(22, integer + 15 * bl);
        }
        if (index >= 93 && index <= 96) {
            Integer integer = list.get(23);
            list.set(23, integer + 15 * bl);
        }

    }

    //计算电压平均值
    public static Double avg(VoltageQualified voltageQualified) {
        if (voltageQualified.getNotNullPoint() != 0) {
            return voltageQualified.getTotalU() / voltageQualified.getNotNullPoint();
        } else {
            return 0D;
        }
    }


    /**
     * 陈烈新说配变先按照以下配变电压等级规则来计算 不按照台账表里面的电压等级 按照具体取到的数值来规定电压阈值
     * 判断配变的电压范围需不需要*根号三
     *
     * @param voltageQualified 当前vo对象
     * @param
     * @param currentDy        当前电压值
     *                         <p>
     *                         配变
     *                         <=40,数据无效
     *                         (40,74),原始数值*根号3*100，再跟10kv做比较计算
     *                         [74,130),原始数值*100，再跟10kv做比较计算
     *                         [130,154),数据无效
     *                         (154,286),原始数值跟220v比较计算
     *                         >=286,数据无效
     */
    public static void pbMagnification(VoltageQualified voltageQualified, Double currentDy) {

//        if (seriousnessMap != null) {
//            Double yzUper = seriousnessMap.get(gx.getUp());
//            Double yzDown = seriousnessMap.get(gx.getDown());
//            voltageQualified.setYzYhPbUper(yzUper);
//            voltageQualified.setYzYhPbDown(yzDown);
//        }
//        voltageQualified.setEffectiveDataUper(effectiveDataMap.get(gx.getUp()));
//        voltageQualified.setEffectiveDataLower(effectiveDataMap.get(gx.getDown()));

        if (currentDy <= 40) {
            voltageQualified.setValid("2");
            voltageQualified.setVoltage(currentDy);
        } else if (currentDy > 40 && currentDy < 74) {

            voltageQualified.setValid("1");
            voltageQualified.setVoltage(currentDy * 100 * 1.732);
            voltageQualified.setUp(10700D);
            voltageQualified.setDown(9000D);
            voltageQualified.setYzYhPbUper(11500D);
            voltageQualified.setYzYhPbDown(8500D);
            voltageQualified.setEffectiveDataUper(13000D);
            voltageQualified.setEffectiveDataLower(7000D);
        } else if (currentDy > 74 && currentDy < 130) {

            voltageQualified.setValid("1");
            voltageQualified.setVoltage(currentDy * 100);
            voltageQualified.setUp(10700D);
            voltageQualified.setDown(9000D);
            voltageQualified.setYzYhPbUper(11500D);
            voltageQualified.setYzYhPbDown(8500D);
            voltageQualified.setEffectiveDataUper(13000D);
            voltageQualified.setEffectiveDataLower(7000D);

        } else if (currentDy >= 130 && currentDy < 154) {
            voltageQualified.setValid("2");
            voltageQualified.setVoltage(0D);
        } else if (currentDy >= 154 && currentDy < 286) {
            voltageQualified.setValid("1");
            voltageQualified.setVoltage(currentDy);
            voltageQualified.setUp(235.4);
            voltageQualified.setDown(198D);
            voltageQualified.setYzYhPbUper(253D);
            voltageQualified.setYzYhPbDown(187D);
            voltageQualified.setEffectiveDataUper(286D);
            voltageQualified.setEffectiveDataLower(154D);
        } else if (currentDy >= 286) {
            voltageQualified.setValid("2");
            voltageQualified.setVoltage(currentDy);
        }
    }


    //填充用户配变长期越上集合
    public static void yhLongTimeUper(VoltageQualified voltageQualified,Integer bl,Integer dyCount) {
        StringJoiner highVoltage = voltageQualified.getHighVoltage();
        //获取当前电压值
        Double voltage = voltageQualified.getVoltage();
        ArrayList<Integer> yhLongTimeUperArray = voltageQualified.getYhLongTimeUperArray();
        Integer index = voltageQualified.getIndex();
        if (voltage > voltageQualified.getUp() && voltage <= voltageQualified.getYzYhPbUper()) {
            voltageQualified.setHighTime(voltageQualified.getHighTime() + 15 * bl);
            highVoltage.add(index + ":" + voltage);
            yhLongTimeUperArray.add(index);
            if (dyCount == 96|| dyCount == 48 && voltageQualified.getIsYX() != null && voltageQualified.getIsYX().equals("1")) {
                voltageQualified.setGaoSum(voltageQualified.getGaoSum() + 1);
            }
            if (dyCount==24 || dyCount == 4 || dyCount ==1){
                voltageQualified.setGaoSum(voltageQualified.getGaoSum() + 1);
            }
            voltageQualified.setIsYX("1");
        }
    }

    //填充用户配变长期越下集合
    public static void yhLongTimeDown(VoltageQualified voltageQualified,Integer bl,Integer dyCount) {
        Double voltage = voltageQualified.getVoltage();
        StringJoiner lowVoltage = voltageQualified.getLowVoltage();
        ArrayList<Integer> yhLongTimeDownArray = voltageQualified.getYhLongTimeDownArray();
        Integer index = voltageQualified.getIndex();
        if (voltage < voltageQualified.getDown() && voltage >= voltageQualified.getYzYhPbDown()) {
            voltageQualified.setLowTime(voltageQualified.getLowTime() + 15 * bl);
            if (dyCount == 96|| dyCount == 48 && voltageQualified.getIsYX() != null && voltageQualified.getIsYX().equals("2")) {
                voltageQualified.setDiSum(voltageQualified.getDiSum() + 1);
            }
            if (dyCount==24 || dyCount == 4 || dyCount ==1){
                voltageQualified.setDiSum(voltageQualified.getDiSum() + 1);
            }
            voltageQualified.setIsYX("2");
            lowVoltage.add(index + ":" + voltage);
            yhLongTimeDownArray.add(index);

        }
    }

    //填充用户配变严重越上集合
    public static void yhYzUp(VoltageQualified voltageQualified,Integer bl) {
        Double voltage = voltageQualified.getVoltage();
        StringJoiner severeHighVoltage = voltageQualified.getSevereHighVoltage();
        ArrayList<Integer> yhSeverityUperArray = voltageQualified.getYhSeverityUperArray();
        Integer index = voltageQualified.getIndex();
        Integer dyCount = voltageQualified.getDyCount();
        if (voltage > voltageQualified.getYzYhPbUper()) {
            voltageQualified.setSevereHighTime(voltageQualified.getSevereHighTime() + 15 * bl);
            severeHighVoltage.add(index + ":" + voltage);
            yhSeverityUperArray.add(index);
//            voltageQualified.setYzGaoSum(voltageQualified.getYzGaoSum() + 1);
            if (dyCount == 96|| dyCount == 48 && voltageQualified.getIsYX() != null &&voltageQualified.getIsYX().equals("3")){
                voltageQualified.setYzGaoSum(voltageQualified.getYzGaoSum() + 1);
            }
            if (voltageQualified.getIsYX() != null && voltageQualified.getIsYX().equals("1")){
                voltageQualified.setGaoSum(voltageQualified.getGaoSum() + 1);
            }
            if (dyCount==24 || dyCount == 4 || dyCount ==1){
                voltageQualified.setYzGaoSum(voltageQualified.getYzGaoSum() + 1);
            }
            voltageQualified.setIsYX("3");
        }
    }

    //填充用户配变严重越下集合
    public static void yhYzDown(VoltageQualified voltageQualified,Integer bl) {
        Double voltage = voltageQualified.getVoltage();
        ArrayList<Integer> yhSeverityDownArray = voltageQualified.getYhSeverityDownArray();
        StringJoiner severelyLowVoltage = voltageQualified.getSeverelyLowVoltage();
        Integer index = voltageQualified.getIndex();
        Integer dyCount = voltageQualified.getDyCount();
        if (voltage < voltageQualified.getYzYhPbDown()) {
            voltageQualified.setSeverelyLowTime(voltageQualified.getSeverelyLowTime() + 15 * bl);
            severelyLowVoltage.add(index + ":" + voltage);
            yhSeverityDownArray.add(index);
//            voltageQualified.setYzDiSum(voltageQualified.getYzDiSum() + 1);
            if (dyCount == 96|| dyCount == 48 && voltageQualified.getIsYX() != null && voltageQualified.getIsYX().equals("4")){
                voltageQualified.setYzDiSum(voltageQualified.getYzDiSum() + 1);
            }
            if (voltageQualified.getIsYX() != null && voltageQualified.getIsYX().equals("2")){
                voltageQualified.setYzDiSum(voltageQualified.getDiSum() + 1);
            }
            if (dyCount==24 || dyCount == 4 || dyCount ==1){
                voltageQualified.setYzDiSum(voltageQualified.getYzDiSum() + 1);
            }
            voltageQualified.setIsYX("4");
        }
    }


    //判断用户类型 长期高低电压 严重高低电压
    public static void consType(VoltageQualified voltageQualified) {

        //1长期高 2长期低 3严重高  4严重低
        StringJoiner stringJoiner = new StringJoiner(",");
        ArrayList<Integer> yhLongTimeUperArray = voltageQualified.getYhLongTimeUperArray();
        ArrayList<Integer> yhLongTimeDownArray = voltageQualified.getYhLongTimeDownArray();
        ArrayList<Integer> yhSeverityUperArray = voltageQualified.getYhSeverityUperArray();
        ArrayList<Integer> yhSeverityDownArray = voltageQualified.getYhSeverityDownArray();

        //判断是按96个点来算 还是24个点来算
        if (voltageQualified.getDyCount() == 24) {
            boolean g = FormulaUtils.isLx2Num(yhLongTimeUperArray);
            boolean d = FormulaUtils.isLx2Num(yhLongTimeDownArray);
            boolean sg = FormulaUtils.isLx2Num(yhSeverityUperArray);
            boolean sd = FormulaUtils.isLx2Num(yhSeverityDownArray);

            pbType(stringJoiner, g, d, sg, sd);
        } else if (voltageQualified.getDyCount() == 96) {

            boolean longTimeUper = isLxNum(yhLongTimeUperArray);
            if (longTimeUper) {
                stringJoiner.add("1");
            }

            boolean longTimeDown = isLxNum(yhLongTimeDownArray);
            if (longTimeDown) {
                stringJoiner.add("2");
            }

            boolean severityUper = isLxNum(yhSeverityUperArray);
            if (severityUper) {
                stringJoiner.add("3");
            }

            boolean severityDown = isLxNum(yhSeverityDownArray);
            if (severityDown) {
                stringJoiner.add("4");
            }
        }
        voltageQualified.setConsType(stringJoiner.toString());
    }

    //给配变设置状态 1.长期高 2.长期低 3.严重高 4.严重低
    public static void pbType(StringJoiner stringJoiner, boolean g, boolean d, boolean sg, boolean sd) {
        if (g) {
            stringJoiner.add("1");
        }
        if (d) {
            stringJoiner.add("2");
        }
        if (sg) {
            stringJoiner.add("3");
        }
        if (sd) {
            stringJoiner.add("4");
        }
    }


    //判断用户类型 长期高低电压 严重高低电压
    public static void consCsAndTime(VoltageQualified voltageQualified) {
        ArrayList<Integer> yhLongTimeUperArray = voltageQualified.getYhLongTimeUperArray();
        ArrayList<Integer> yhLongTimeDownArray = voltageQualified.getYhLongTimeDownArray();
        ArrayList<Integer> yhSeverityUperArray = voltageQualified.getYhSeverityUperArray();
        ArrayList<Integer> yhSeverityDownArray = voltageQualified.getYhSeverityDownArray();
        //判断是按96个点来算 还是24个点来算
        if (voltageQualified.getDyCount() == 24) {
            int gaoSum = FormulaUtils.countConsecutive(yhLongTimeUperArray, 1,4);
            int diSum = FormulaUtils.countConsecutive(yhLongTimeDownArray, 1,4);
            int yzGaoSum = FormulaUtils.countConsecutive(yhSeverityUperArray, 1,4);
            int yzDiSum = FormulaUtils.countConsecutive(yhSeverityDownArray, 1,4);
            voltageQualified.setHighCs(gaoSum);
            voltageQualified.setLowCs(diSum);
            voltageQualified.setSevereHighCs(yzGaoSum);
            voltageQualified.setSeverelyLowCs(yzDiSum);
        } else if (voltageQualified.getDyCount() == 96) {
            int gaoSum = FormulaUtils.countConsecutive(yhLongTimeUperArray, 4);
            int diSum = FormulaUtils.countConsecutive(yhLongTimeDownArray, 4);
            int yzGaoSum = FormulaUtils.countConsecutive(yhSeverityUperArray, 4);
            int yzDiSum = FormulaUtils.countConsecutive(yhSeverityDownArray, 4);
            voltageQualified.setHighCs(gaoSum);
            voltageQualified.setLowCs(diSum);
            voltageQualified.setSevereHighCs(yzGaoSum);
            voltageQualified.setSeverelyLowCs(yzDiSum);
        } else if (voltageQualified.getDyCount() == 48) {
            int gaoSum = FormulaUtils.countConsecutive(yhLongTimeUperArray, 2,2);
            int diSum = FormulaUtils.countConsecutive(yhLongTimeDownArray, 2,2);
            int yzGaoSum = FormulaUtils.countConsecutive(yhSeverityUperArray, 2,2);
            int yzDiSum = FormulaUtils.countConsecutive(yhSeverityDownArray, 2,2);
            voltageQualified.setHighCs(gaoSum);
            voltageQualified.setLowCs(diSum);
            voltageQualified.setSevereHighCs(yzGaoSum);
            voltageQualified.setSeverelyLowCs(yzDiSum);
        } else if (voltageQualified.getDyCount() == 4) {
            int gaoSum = FormulaUtils.countConsecutive(yhLongTimeUperArray, 1,24);
            int diSum = FormulaUtils.countConsecutive(yhLongTimeDownArray, 1,24);
            int yzGaoSum = FormulaUtils.countConsecutive(yhSeverityUperArray, 1,24);
            int yzDiSum = FormulaUtils.countConsecutive(yhSeverityDownArray, 1,24);
            voltageQualified.setHighCs(gaoSum);
            voltageQualified.setLowCs(diSum);
            voltageQualified.setSevereHighCs(yzGaoSum);
            voltageQualified.setSeverelyLowCs(yzDiSum);
        }else if (voltageQualified.getDyCount() == 1) {
            int gaoSum = FormulaUtils.countConsecutive(yhLongTimeUperArray, 1);
            int diSum = FormulaUtils.countConsecutive(yhLongTimeDownArray, 1);
            int yzGaoSum = FormulaUtils.countConsecutive(yhSeverityUperArray, 1);
            int yzDiSum = FormulaUtils.countConsecutive(yhSeverityDownArray, 1);
            voltageQualified.setHighCs(gaoSum);
            voltageQualified.setLowCs(diSum);
            voltageQualified.setSevereHighCs(yzGaoSum);
            voltageQualified.setSeverelyLowCs(yzDiSum);
        }
    }


    //判断一个集合是否有2个连续数字
    public static boolean isLx2Num(List<Integer> integers) {
        if (integers.size() < 1) {
            return false;
        }

        for (int i = 0; i < integers.size(); i++) {
            if (i + 1 < integers.size()) {
                Integer integer = integers.get(i);
                if (integers.get(i + 1) == integer + 4) {
                    return true;
                }
            }
        }
        return false;
    }

    public static int countConsecutive(List<Integer> numbers, int consecutiveCount) {
        int count = 0;
        Set<Integer> usedNumbers = new HashSet<>();

        for (int i = 0; i < numbers.size(); i++) {
            if (usedNumbers.contains(numbers.get(i))) {
                continue; // 跳过已使用的数字
            }

            int currentCount = 1;
            usedNumbers.add(numbers.get(i));

            for (int j = i + 1; j < numbers.size(); j++) {
                if (numbers.get(j) - numbers.get(j - 1) == 1 && !usedNumbers.contains(numbers.get(j))) {
                    currentCount++;
                    usedNumbers.add(numbers.get(j));
                } else {
                    break; // 不再是连续序列，提前结束内循环
                }
            }

            if (currentCount >= consecutiveCount) {
                count++;
            }
        }

        return count;
    }



    public static int countConsecutive(List<Integer> numbers, int consecutiveCount, int maxGap) {
        int count = 0; // 计数器，用于记录满足条件的序列数量
        Set<Integer> usedNumbers = new HashSet<>(); // 用于记录已经使用过的数字的集合

        for (int i = 0; i < numbers.size(); i++) {
            if (usedNumbers.contains(numbers.get(i))) {
                continue; // 跳过已使用的数字
            }

            int currentCount = 1; // 当前连续序列的长度，初始为1，因为已经找到一个数字
            usedNumbers.add(numbers.get(i)); // 将当前数字标记为已使用

            for (int j = i + 1; j < numbers.size(); j++) {
                int gap = numbers.get(j) - numbers.get(j - 1);
                if ((gap == 1 || gap <= maxGap) && !usedNumbers.contains(numbers.get(j))) {
                    currentCount++; // 如果下一个数字与前一个数字相差1或小于等于最大间隔，并且未被使用过，则将连续序列长度加1
                    usedNumbers.add(numbers.get(j)); // 将当前数字标记为已使用
                } else {
                    break; // 不再是连续序列，提前结束内循环
                }
            }

            if (currentCount >= consecutiveCount) {
                count++; // 如果当前连续序列的长度大于等于指定的连续次数，则计数器加1
            }
        }

        return count; // 返回满足条件的序列数量
    }


    public static void main(String[] args) {
    }

    //判断一个集合是否有5个连续的数字
    public static boolean isLxNum(ArrayList<Integer> integers) {
        if (integers.size() < 5) {
            return false;
        }
        //长度
        for (int i = 0; i < integers.size(); i++) {
            if (i + 4 < integers.size()) {
                Integer tempNum = integers.get(i);
                if (integers.get(i + 1) == tempNum + 1 && integers.get(i + 2) == tempNum + 2 && integers.get(i + 3) == tempNum + 3
                        && integers.get(i + 4) == tempNum + 4) {
                    return true;
                }
            }

        }
        return false;
    }

    //判断一个集合是否有8个连续数字
    public static Boolean isLx8Num(ArrayList<Integer> integers) {
        //集合长度小于8直接去除
        if (integers.size() < 8) {
            return false;
        }
        for (int i = 0; i < integers.size(); i++) {
            if (i + 7 < integers.size()) {
                Integer integer = integers.get(i);
                if (integers.get(i + 1) == integer + 1 && integers.get(i + 2) == integer + 2 && integers.get(i + 3) == integer + 3
                        && integers.get(i + 4) == integer + 4 && integers.get(i + 5) == integer + 5 && integers.get(i + 6) == integer + 6
                        && integers.get(i + 7) == integer + 7) {
                    return true;
                }
            }
        }
        return false;

    }

    /**
     * 获取连续相邻数字次数
     *
     * @param list 集合
     * @param num  相邻范围
     * @return 返回相邻次数
     */
    public static int isContinuousFrequency(List<Integer> list, int num) {
        int frequencyNum = 0;
        //去重排序
        List<Integer> distinctList = list.stream().distinct().sorted().collect(Collectors.toList());
        int size = distinctList.size();
        //获取向前的索引下标
        int forwardIndex = num - 1;
        for (int i = 0; i < size; i++) {
            int currentIndex = i + forwardIndex;
            if (currentIndex < size) {
                //当期索引下标的值
                Integer indexValue = distinctList.get(i);
                //增加num后索引下标的值
                Integer integer = distinctList.get(currentIndex);
                //索引下前下标+当期索引下标获取的值
                int i2 = forwardIndex + indexValue;
                if (integer == i2) {
                    //统计次数
                    frequencyNum++;
                    //当前i向前+ forwardIndex
                    i += forwardIndex;
                }
            } else {
                break;
            }
        }
        return frequencyNum;
    }


    //判断一个集合出现四个连续的数字的次数
    public static Integer isLxNum2(ArrayList<Integer> integers) {

        if (integers.size() < 4) {
            return 0;
        }
        int count = 0;
        for (int i = 0; i < integers.size(); i++) {
            if (i + 3 < integers.size()) {
                Integer integer = integers.get(i);
                if (integers.get(i + 1) == integer + 1 && integers.get(i + 2) == integer + 2 && integers.get(i + 3) == integer + 3) {
                    count++;
                    i += 3;
                }
            }
        }
        return count;
    }


    //判断一个集合出现八个连续的数字次数
    public static Integer isLxNum8(ArrayList<Integer> integers) {
        if (integers.size() < 8) {
            return 0;
        }

        int count = 0;
        for (int i = 0; i < integers.size(); i++) {
            if (i + 7 < integers.size()) {
                Integer integer = integers.get(i);
                if (integers.get(i + 1) == integer + 1 && integers.get(i + 2) == integer + 2 && integers.get(i + 3) == integer + 3
                        && integers.get(i + 4) == integer + 4 && integers.get(i + 5) == integer + 5 && integers.get(i + 6) == integer + 6
                        && integers.get(i + 7) == integer + 7) {
                    count++;
                    i += 7;
                }
            }
        }
        return count;
    }


    //配变越上越下次数
    public static void Pbcs(VoltageQualified voltageQualified) {
        ArrayList<Integer> yhLongTimeUperArray = voltageQualified.getYhLongTimeUperArray();
        ArrayList<Integer> yhLongTimeDownArray = voltageQualified.getYhLongTimeDownArray();
        ArrayList<Integer> yhSeverityUperArray = voltageQualified.getYhSeverityUperArray();
        ArrayList<Integer> yhSeverityDownArray = voltageQualified.getYhSeverityDownArray();
        //1长期高 2长期低 3严重高  4严重低
        StringJoiner stringJoiner = new StringJoiner(",");
        if (voltageQualified.getDyCount() == 24) {
            if (yhSeverityUperArray.size() > 1) {
                stringJoiner.add("3");
                voltageQualified.setPbcs(yhSeverityUperArray.size());
            }
            if (yhLongTimeUperArray.size() > 1) {
                stringJoiner.add("1");
                voltageQualified.setPbcs(yhLongTimeUperArray.size());
            }
            if (yhSeverityDownArray.size() > 1) {
                stringJoiner.add("4");
                voltageQualified.setPbcs(yhSeverityDownArray.size());
            }
            if (yhLongTimeDownArray.size() > 1) {
                stringJoiner.add("2");
                voltageQualified.setPbcs(yhLongTimeDownArray.size());
            }
        } else if (voltageQualified.getDyCount() == 96) {
            boolean longTimeUper = isLxNum(yhLongTimeUperArray);
            boolean longTimeDown = isLxNum(yhLongTimeDownArray);
            boolean severityUper = isLxNum(yhSeverityUperArray);
            boolean severityDown = isLxNum(yhSeverityDownArray);
            if (severityUper) {
                stringJoiner.add("3");
                Integer lxNum2 = isLxNum2(yhSeverityUperArray);
                voltageQualified.setPbcs(lxNum2);
            }
            if (longTimeUper) {
                stringJoiner.add("1");
                Integer lxNum2 = isLxNum2(yhLongTimeUperArray);
                voltageQualified.setPbcs(lxNum2);
            }
            if (severityDown) {
                stringJoiner.add("4");
                Integer lxNum2 = isLxNum2(yhSeverityDownArray);
                voltageQualified.setPbcs(lxNum2);
            }
            if (longTimeDown) {
                stringJoiner.add("2");
                Integer lxNum2 = isLxNum2(yhLongTimeDownArray);
                voltageQualified.setPbcs(lxNum2);
            }

        }

        voltageQualified.setPbType(stringJoiner.toString());


    }


    //配变功率因数计算
    public static Double powerFactor(Double yg, Double ug) {
        return yg / (Math.sqrt(((yg * yg) + (ug * ug))));
    }


    /**
     * @param yg 当前有功值
     * @param wg 当前无功值
     * @return
     */
    //配变视在功率计算 : 有功的平方 + 无功的平方 开方
    public static Double apparentPower(Double yg, Double wg) {
        return (Math.sqrt(((yg * yg) + (wg * wg))));
    }

    /**
     * @param apparentPower 视在功率
     * @param rated         额定容量
     * @return
     */
    //配变负载率计算
    public static Double loadRate(Double apparentPower, Double rated) {
        if (rated != 0) {
            double s = apparentPower / rated;
            return s * 100;
        } else {
            return 0D;
        }
    }


    public static void pbYzYs(VoltageQualified voltageQualified) {

        Integer yzyxTime = voltageQualified.getYzyxTime();
        Double u = voltageQualified.getVoltage();
        if (u > voltageQualified.getYzYhPbUper()) {
            yzyxTime += 15;
            voltageQualified.setYzyxTime(yzyxTime);
        }

    }


    //三相不平衡计算公式:（最大电流-最小电流）/最大电流
    public static Double triphase(Double max, Double min) {
        return (max - min) / max;
    }

    //计算电压波动率计算公式: （最高电压-额定电压/额定电压）×100%
    public static Double voltageFluctuation(Double maxVoltage, Double minVoltage, String dydj) {
        //根据电压等级 获取额定电压值
//        Double desc = Constant.VoltEnum.getDesc(dydj);
        //暂时写死380v
        Double desc = 220D;
//        if (desc != null && desc != 0) {
//            return (maxVoltage - desc) / desc;
//        } else {
//            return 0D;
//        }

        if (maxVoltage != 0 && minVoltage != 0) {
            return (maxVoltage - minVoltage) / desc;
        } else {
            return 0D;
        }

    }

    /**
     * @param voltageQualified 当前vo对象
     * @param gx               gxVo对象
     * @param blMap            倍率map
     * @param currentDy        当前电压值
     */
    //用户电压范围规则 判断需不需要*根号三 或者 需不需要*倍率
    //陈烈新说用户先按照以下用户电压等级规则来计算
    public static void yhMagnification(VoltageQualified voltageQualified, Gx gx, HashMap<String, Integer> blMap, Double currentDy) {
        if (VoltageLevelEnum.getCode(gx.getDydj()) > 2) {
            if (currentDy <= 40) {
                voltageQualified.setValid("2");
                voltageQualified.setVoltage(currentDy);
            } else if (currentDy > 40 && currentDy < 74) {
                voltageQualified.setValid("1");
                voltageQualified.setVoltage(currentDy * blMap.get(gx.getDydj()) * 1.732);

            } else if (currentDy >= 74 && currentDy < 130) {
                voltageQualified.setValid("1");
                voltageQualified.setVoltage(currentDy * blMap.get(gx.getDydj()));
            } else if (currentDy >= 130) {
                voltageQualified.setValid("2");
                voltageQualified.setVoltage(currentDy);
            }
        } else if (VoltageLevelEnum.getCode(gx.getDydj()) == 2) {
            if (currentDy <= 154) {
                voltageQualified.setValid("2");
                voltageQualified.setVoltage(currentDy);
            } else if (currentDy > 154 && currentDy < 286) {
                voltageQualified.setValid("1");
                voltageQualified.setVoltage(currentDy * 1.732);
            } else if (currentDy >= 286 && currentDy < 494) {
                voltageQualified.setValid("1");
                voltageQualified.setVoltage(currentDy);
            } else if (currentDy >= 494) {
                voltageQualified.setValid("2");
                voltageQualified.setVoltage(currentDy);
            }
        } else if (VoltageLevelEnum.getCode(gx.getDydj()) == 1) {
            if (currentDy <= 154) {
                voltageQualified.setValid("2");
                voltageQualified.setVoltage(currentDy);
            } else if (currentDy > 154 && currentDy < 286) {
                voltageQualified.setValid("1");
                voltageQualified.setVoltage(currentDy);
            } else if (currentDy >= 286) {
                voltageQualified.setValid("2");
                voltageQualified.setVoltage(currentDy);
            }
        }
    }

    public static void setVoltLevel(double voltsAvg, Gx gx,VoltageQualified voltageQualified) {
        if (voltsAvg >= 154 && voltsAvg <= 286){
            gx.setUp("0107U");
            gx.setDown("0107D");
            gx.setDydj("0107");
            gx.setVoltBm("0107");
            voltageQualified.setDydj("0107");
        } else if (voltsAvg >= 304 && voltsAvg <= 456) {
            gx.setUp("0108U");
            gx.setDown("0108D");
            gx.setDydj("0108");
            gx.setVoltBm("0108");
            voltageQualified.setDydj("0108");
        } else if (voltsAvg >= 4800 && voltsAvg <= 7200) {
            gx.setUp("0116U");
            gx.setDown("0116D");
            gx.setDydj("0116");
            gx.setVoltBm("0116");
            voltageQualified.setDydj("0116");
        } else if (voltsAvg >= 8000 && voltsAvg <= 12000) {
            gx.setUp("0117U");
            gx.setDown("0117D");
            gx.setDydj("0117");
            gx.setVoltBm("0117");
            voltageQualified.setDydj("0117");
        } else if (voltsAvg >= 16000 && voltsAvg <= 24000) {
            gx.setUp("0119U");
            gx.setDown("0119D");
            gx.setDydj("0119");
            gx.setVoltBm("0119");
            voltageQualified.setDydj("0119");
        } else if (voltsAvg >= 28000 && voltsAvg <= 42000) {
            gx.setUp("0121U");
            gx.setDown("0121D");
            gx.setDydj("0121");
            gx.setVoltBm("0121");
            voltageQualified.setDydj("0121");
        } else if (voltsAvg >= 52800 && voltsAvg <= 79200) {
            gx.setUp("0122U");
            gx.setDown("0122D");
            gx.setDydj("0122");
            gx.setVoltBm("0122");
            voltageQualified.setDydj("0122");
        } else if (voltsAvg >= 88000 && voltsAvg <= 132000) {
            gx.setUp("0123U");
            gx.setDown("0123D");
            gx.setDydj("0123");
            gx.setVoltBm("0123");
            voltageQualified.setDydj("0123");
        } else if (voltsAvg >= 176000 && voltsAvg <= 264000) {
            gx.setUp("0124U");
            gx.setDown("0124D");
            gx.setDydj("0124");
            gx.setVoltBm("0124");
            voltageQualified.setDydj("0124");
        } else if (voltsAvg > 264000 && voltsAvg <= 396000) {
            gx.setUp("0125U");
            gx.setDown("0125D");
            gx.setDydj("0125");
            gx.setVoltBm("0125");
            voltageQualified.setDydj("0125");
        } else if (voltsAvg >= 400000 && voltsAvg <= 600000) {
            gx.setUp("0126U");
            gx.setDown("0126D");
            gx.setDydj("0126");
            gx.setVoltBm("0126");
            voltageQualified.setDydj("0126");
        } else if (voltsAvg > 600000 && voltsAvg <= 900000) {
            gx.setUp("0127U");
            gx.setDown("0127D");
            gx.setDydj("0127");
            gx.setVoltBm("0127");
            voltageQualified.setDydj("0127");
        }else {
            voltageQualified.setExceptionCode("500");
        }
    }


    /**
     * @param gx gxVo对象
     *           <p>
     *           判断当前电表需不需要修正电压值
     */
    public static boolean isYhMagnification(Gx gx, List<VoltU1_96> u1_96List, VoltageQualified voltageQualified) {
        int count = 0;
        for (int i = 0; i < u1_96List.size(); i++) {
            String v = u1_96List.get(i).getV();
            if (StringUtils.isNotEmpty(v)) {
                double u = Double.parseDouble(v);
                if (VoltageLevelEnum.getCode(gx.getDydj()) > 2) {
                    if (u <= 40) {
                    } else if (u > 40 && u < 74) {
                        count++;
                    } else if (u > 74 && u < 130) {
                        count++;
                    }
                } else if (VoltageLevelEnum.getCode(gx.getDydj()) == 2) {
                    if (u <= 154) {
                    } else if (u > 154 && u < 286) {
                        count++;
                    } else if (u > 286 && u < 494) {
                        count++;
                    }
                }
            }
        }
        return count > voltageQualified.getDyPCount() / 2;
    }

//    public static boolean isYhMagnification( String s, List<Double> u1_96List) {
//        int count = 0;
//        for (int i = 0; i < u1_96List.size(); i++) {
//                if (VoltageLevelEnum.getCode(s) > 2) {
//                    if (u1_96List.get(i) <= 40) {
//                    } else if (u1_96List.get(i) > 40 && u1_96List.get(i) < 74) {
//                        count++;
//                    } else if (u1_96List.get(i) > 74 && u1_96List.get(i) < 130) {
//                        count++;
//                    }
//                } else if (VoltageLevelEnum.getCode(s) == 2) {
//                    if (u1_96List.get(i) <= 154) {
//                    } else if (u1_96List.get(i) > 154 && u1_96List.get(i) < 286) {
//                        count++;
//                    }
//                }
//        }
//        return count > 12;
//    }


    /**
     * 陈烈新说配变先按照以下配变电压等级规则来计算 不按照台账表里面的电压等级 按照具体取到的数值来规定电压阈值
     * 判断配变的电压范围需不需要*根号三
     *
     * @param voltageQualified 当前vo对象
     * @param gx               gx对象
     * @param currentDy        当前电压值
     *                         <p>
     *                         配变
     *                         <=40,数据无效
     *                         (40,74),原始数值*根号3*100，再跟10kv做比较计算
     *                         [74,130),原始数值*100，再跟10kv做比较计算
     *                         [130,154),数据无效
     *                         (154,286),原始数值跟220v比较计算
     *                         >=286,数据无效
     */
    public static void pbMagnification(VoltageQualified voltageQualified, Gx gx, Double currentDy) {
        if (currentDy < 130) {
            voltageQualified.setValid("2");
            voltageQualified.setVoltage(0D);
        } else if (currentDy >= 130 && currentDy < 154) {
            voltageQualified.setValid("2");
            voltageQualified.setVoltage(0D);
        } else if (currentDy >= 154 && currentDy < 286) {
            voltageQualified.setValid("1");
            voltageQualified.setVoltage(currentDy);
            voltageQualified.setUp(235.4);
            voltageQualified.setDown(198D);
            voltageQualified.setYzYhPbUper(253D);
            voltageQualified.setYzYhPbDown(187D);
            voltageQualified.setEffectiveDataUper(286D);
            voltageQualified.setEffectiveDataLower(154D);
        } else if (currentDy >= 286) {
            voltageQualified.setValid("2");
            voltageQualified.setVoltage(0D);
        }
    }


    public static boolean isPbMagnification(VoltageQualified voltageQualified, List<VoltU1_96> u1_96List) {
        int count = 0;
        for (int i = 0; i < u1_96List.size(); i++) {
            String v = u1_96List.get(i).getV();
            if (StringUtils.isNotEmpty(v)) {
                double u = Double.parseDouble(v);
                voltageQualified.setVoltage(u);
                if (u <= 40) {
                    voltageQualified.setValid("2");
                } else if (u > 40 && u < 74) {
                    voltageQualified.setValid("2");
                } else if (u > 74 && u < 130) {
                    voltageQualified.setValid("2");
                } else if (u >= 130 && u < 154) {
                } else if (u >= 154 && u < 286) {
                    voltageQualified.setValid("1");
                    count++;
                } else if (u >= 286) {
                }
            }
        }
        return count > voltageQualified.getDyPCount() / 2;
    }


    /**
     * 给配变表加入高低电压 需要标准电压等字段 此方法专门为高低电压配变服务
     *
     * @param voltageQualified
     * @param gx
     * @param currentDy
     * @return
     */
    public static VoltageQualified pbMagnification2(VoltageQualified voltageQualified, Gx gx, Double currentDy) {

        VoltageQualified vo = VoltageQualified.builder().build();
        if (currentDy <= 40) {
            vo.setValid("2");
            vo.setVoltage(0D);

        } else if (currentDy > 40 && currentDy < 74) {

            vo.setValid("1");
            vo.setVoltage(currentDy * 100 * 1.732);
            vo.setUp(10700D);
            vo.setDown(9000D);
            vo.setYzYhPbUper(11500D);
            vo.setYzYhPbDown(8500D);
            vo.setEffectiveDataUper(13000D);
            vo.setEffectiveDataLower(7000D);
            vo.setStandard(10000D);
            vo.setHigh(1500D);
            vo.setLow(1000D);
        } else if (currentDy > 74 && currentDy < 130) {

            vo.setValid("1");
            vo.setVoltage(currentDy * 100);
            vo.setUp(10700D);
            vo.setDown(9000D);
            vo.setYzYhPbUper(11500D);
            vo.setYzYhPbDown(8500D);
            vo.setEffectiveDataUper(13000D);
            vo.setEffectiveDataLower(7000D);
            vo.setStandard(10000D);
            vo.setHigh(1500D);
            vo.setLow(1000D);

        } else if (currentDy >= 130 && currentDy < 154) {
            vo.setValid("2");
            vo.setVoltage(0D);
        } else if (currentDy >= 154 && currentDy < 286) {
            vo.setValid("1");
            vo.setVoltage(currentDy);
            vo.setUp(235.4);
            vo.setDown(198D);
            vo.setYzYhPbUper(253D);
            vo.setYzYhPbDown(176D);
            vo.setEffectiveDataUper(286D);
            vo.setEffectiveDataLower(154D);
            vo.setStandard(220D);
            vo.setHigh(33D);
            vo.setLow(22D);
        } else if (currentDy >= 286) {
            vo.setValid("2");
            vo.setVoltage(0D);
        }
        return vo;

    }


    public static List<Double> pbMagnificationwx(List<Double> integers) {

//        if (seriousnessMap != null) {
//            Double yzUper = seriousnessMap.get(gx.getUp());
//            Double yzDown = seriousnessMap.get(gx.getDown());
//            voltageQualified.setYzYhPbUper(yzUper);
//            voltageQualified.setYzYhPbDown(yzDown);
//        }
//        voltageQualified.setEffectiveDataUper(effectiveDataMap.get(gx.getUp()));
//        voltageQualified.setEffectiveDataLower(effectiveDataMap.get(gx.getDown()));

        List<Double> integerList = new ArrayList<>();
        for (Double integer : integers) {
            if (integer <= 40) {
            } else if (integer > 40 && integer < 74) {
                integerList.add(integer);

            } else if (integer > 74 && integer < 130) {

                integerList.add(integer);

            } else if (integer >= 130 && integer < 154) {

            } else if (integer >= 154 && integer < 286) {
                integerList.add(integer);
            } else if (integer >= 286) {

            }

        }

        return integerList;

    }


    /**
     * 高低电压评判标准：
     * 1.高电压 : 三相最高电压 - 标准电压 / 标准电压 > 15%
     * 2.低电压 : 标准电压 - 三相最低电压 / 标准电压 > 10%
     */
    //是否高电压
    public static Boolean isGao(Double max, Double standard, Double voltDouble) {
        if (max == null || standard == null || voltDouble == null) {
            return false;
        }
        if (((max - standard) / standard) > 0.15) {
            return true;
        }
        return false;
    }


    /**
     * 高低电压评判标准：
     * 1.高电压 : 三相最高电压 - 标准电压 / 标准电压 > 15%
     * 2.低电压 : 标准电压 - 三相最低电压 / 标准电压 > 10%
     */
    //是否低电压
    public static Boolean isLow(Double min, Double standard, Double voltDoubleDown, Double voltDoubleUp) {
        if (min == null || standard == null || voltDoubleDown == null || voltDoubleUp == null) {
            return false;
        }
        if (((standard - min) / standard) > 0.1 && ((standard - min) / standard) < 0.15) {
            return true;
        }
        return false;
    }

    //判断是否是严重高

    /**
     * @param max      三相当中最大值
     * @param standard 严重越高阈值
     * @return
     */
    public static Boolean isSeverityGao(Double max, Double standard) {
        if (max > standard) {
            return true;
        }
        return false;
    }

    //判断是否是严重低

    /**
     * @param min      三相当中最小值
     * @param standard 严重越下阈值
     * @return
     */
    public static Boolean isSeverityLow(Double min, Double standard) {
        if (min < standard) {
            return true;
        }
        return false;
    }


    /**
     * @param integers 传入要判断的集合
     * @param num      传入想要连续的次数
     * @return
     */
    public static PbCsVo isLxNum4(ArrayList<Integer> integers, Integer num) {

        if (integers.size() < num) {
            return null;
        }
        PbCsVo pbCsVo = new PbCsVo();
        int count = 0;
        int sum = 0;
        int size = 0;
        double time = 0;
        for (int i = 0; i < integers.size(); i++) {

            Integer integer = integers.get(i);
            if (i == 0) {
                sum = integer;
            }
            if (sum == integer) {
                size++;
            } else {
                if (size >= num) {
                    time += (size - 1) * 15;
                    count++;
                }
                size = 1;
                sum = integer;
            }
            if (i == integers.size() - 1) {
                if (size >= num) {
                    time += (size - 1) * 15;
                    count++;
                }
            }
            sum++;
        }
        pbCsVo.setPbCs(count);
        pbCsVo.setPbCsTime(time);
        return pbCsVo;
    }

    /**
     * @param integers 传入要判断的集合
     * @return
     */
    public static PbCsVo isPb24CsAndTime(ArrayList<Integer> integers) {

        if (integers.size() < 2) {
            return null;
        }
        PbCsVo pbCsVo = new PbCsVo();
        int count = 0;
        int sum = 0;
        int size = 0;
        double time = 0;
        for (int i = 0; i < integers.size(); i++) {

            Integer integer = integers.get(i);
            if (i == 0) {
                sum = integer;
            }
            if (sum == integer) {
                size++;
            } else {
                if (size >= 2) {
                    time += (size - 1) * 60;
                    count++;
                }
                size = 1;
                sum = integer;
            }
            if (i == integers.size() - 1) {
                if (size >= 2) {
                    time += (size - 1) * 60;
                    count++;
                }
            }
            sum += 4;
        }
        pbCsVo.setPbCs(count);
        pbCsVo.setPbCsTime(time);
        return pbCsVo;
    }


    /**
     * @param integers 传入要判断的集合
     * @param num      传入想要连续的次数
     * @return
     */
    public static Integer isLxNum24(ArrayList<Integer> integers, Integer num) {

        if (integers.size() < num) {
            return null;
        }
        int count = 0;
        int sum = 0;
        int size = 0;

        for (int i = 0; i < integers.size(); i++) {

            Integer integer = integers.get(i);
            if (i == 0) {
                sum = integer;
            }
            if (sum == integer) {
                size++;
            } else {
                if (size >= num) {
                    count++;
                }
                size = 1;
                sum = integer;
            }
            if (i == integers.size() - 1) {
                if (size >= num) {
                    count++;
                }
            }
            sum++;
        }
        return count;
    }


    public static Integer isLxNum245(ArrayList<Integer> integers) {

        if (integers.size() < 2) {
            return null;
        }
        int count = 0;
        int sum = 0;
        int size = 0;

        for (int i = 0; i < integers.size(); i++) {

            Integer integer = integers.get(i);
            if (i == 0) {
                sum = integer;
            }
            if (sum == integer) {
                size++;
            } else {
                if (size >= 2) {
                    count++;
                }
                size = 1;
                sum = integer;
            }
            if (i == integers.size() - 1) {
                if (size >= 2) {
                    count++;
                }
            }
            sum += 4;
        }
        return count;
    }

    public static void pbCorrection(VoltageQualified voltageQualified, Double u) {
        voltageQualified.setVoltage(u);
        voltageQualified.setUp(235.4);
        voltageQualified.setDown(198D);
        voltageQualified.setYzYhPbUper(253D);
        voltageQualified.setYzYhPbDown(187D);
        voltageQualified.setEffectiveDataUper(286D);
        voltageQualified.setEffectiveDataLower(154D);
    }

    public static Integer getDyPracticalCount(List<VoltU1_96> voltU1_96s) {
        Integer dyPCount = 0;
        for (int i = 0; i < voltU1_96s.size(); i++) {
            String v = voltU1_96s.get(i).getV();
            if (StringUtils.isNotEmpty(v)) {
                dyPCount++;
            }
        }
        return dyPCount;
    }

    public static Double setLastMonitorTime(Integer index, Integer listSize, VoltageQualified voltageQualified, Integer bl, Double monitorTime, Integer type) {
        if (index == listSize - 1) {
            if (voltageQualified.getIsYx() != null && !voltageQualified.getIsYx().equals(type)) {
                monitorTime += 15 * bl;
            } else if (voltageQualified.getIsYx() != null && voltageQualified.getIsYx().equals(0)) {
                monitorTime += 15 * bl;
            }
        }
        return monitorTime;
    }


    public static List<Double> calibrationVoltage(List<VoltU1_96> u196List, Gx gx,double voltAvg) {
        ArrayList<Double> volts = new ArrayList<>();
        for (int i = 0; i < u196List.size(); i++) {
            String v = u196List.get(i).getV();
            if (v != null && v.length() > 0) {
                Double u = Double.valueOf(v);
                if (voltAvg >= 45 && voltAvg <= 70) {
                    volts.add(u * 1.732 * gx.getPt());
                } else if (voltAvg >= 176 && voltAvg <= 264) {
                    if (gx.getWiringMode().equals("02")) {
                        volts.add(u * gx.getPt());
                    } else if (gx.getWiringMode().equals("03")) {
                        volts.add(u * 1.732 * gx.getPt());
                    } else {
                        volts.add(u * gx.getPt());
                    }
                } else {
                    volts.add(u * gx.getPt());
                }
            } else {
                volts.add(null);
            }
        }
        return volts;

    }

    public static Integer getDyCount(Integer relaDyCount){
        if (relaDyCount <= 1){
            return 1;
        } else if (relaDyCount <= 4) {
            return 4;
        } else if (relaDyCount <= 24) {
            return 24;
        } else if (relaDyCount <= 48) {
            return 48;
        } else if (relaDyCount <= 96) {
            return 96;
        }else {
            return 0;
        }
    }
}
